#ifndef STRING_H_
#define STRING_H_

#include "../base/types.h"
#include "../base/ToStringConvertible.h"
#include "../collections/Array.h"
#include "../memory/ManagedMemory.h"

class StringBuffer;

class String : public ManagedMemory<uchar>, public ToStringConvertible
{
	friend class StringCreator;
	friend class StringTools;
	friend class StringBuffer;
private:
	natural offset;
	natural count;
	String(uchar* val, natural s);

public:
	String();
	String(const String&);
	String(const ToStringConvertible& in);
	virtual ~String();

	String operator=(const String& in);
	String operator=(const ToStringConvertible& in)
	{
		String tmp = ((ToStringConvertible*)(void*)&in)->toString();
		return (operator=(tmp));
	}

	bool equals(const String& in);

	bool operator==(const String& in);
	bool operator!=(const String& in);

	natural length(){return count;}
	bool isEmpty(){return count == 0;}
	uchar operator[](natural i);

	bool startsWith(const String& prefix, natural toffset);
	bool startsWith(const String& prefix){return startsWith(prefix, 0u);}
	bool endsWith(const String& suffix) {return count < suffix.count ? false : startsWith(suffix, count - suffix.count);}

	String toString(){return *this;}
	StringBuffer operator*();
};

#endif /* STRING_H_ */


